//
//  NSString+HVV.m
//  FloatClouds
//
//  Created by 黄威 on 16/8/26.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "NSString+HVV.h"

@implementation NSString (HVV)
//判断字符串是否为Email

- (BOOL) isEmail: (NSString *) emailAddress {
    NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    return [emailTest evaluateWithObject:emailAddress];
}

//判断密码是否大于六位

- (BOOL) isPassWord:(NSString *)password{
    
    if(password.length > 5 && password.length <17)
        
    {
        NSLog(@"密码有效");
        return 1;
        
    }else{
        
        NSLog(@"密码无效");
        
        return 0;
    }
    
    
}

//生成一个40bit的Key

+(NSString *)random40bitString

{
    
    
    NSString *string = [[NSString alloc]init];
    for (int i = 0; i < 40; i++) {
        int number = arc4random() % 36;
        if (number < 10) {
            int figure = arc4random() % 10;
            NSString *tempString = [NSString stringWithFormat:@"%d", figure];
            string = [string stringByAppendingString:tempString];
        }else {
            int figure = (arc4random() % 26) + 97;
            char character = figure;
            NSString *tempString = [NSString stringWithFormat:@"%c", character];
            string = [string stringByAppendingString:tempString];
        }
    }
    NSLog(@"%@", string);

    
    
    return string;
    
}
- (NSString *)encodeToPercentEscapeString: (NSString *) input
{
    NSString*
    outputStr = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                             
                                                                             NULL, /* allocator */
                                                                             
                                                                             (__bridge CFStringRef)input,
                                                                             
                                                                             NULL, /* charactersToLeaveUnescaped */
                                                                             
                                                                             (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                             
                                                                             kCFStringEncodingUTF8);
    
    
    return
    outputStr;
}



@end
